package com.sky.service.user.impl;

import com.github.pagehelper.Page;
import com.sky.context.BaseContext;
import com.sky.mapper.user.MerchantMapper;
import com.sky.mapper.user.ShoppingCartMapper;
import com.sky.pojo.Merchant;
import com.sky.service.user.UserOrderService;
import com.sky.utils.MapUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
@Slf4j
@RequiredArgsConstructor
public class UserOrderServiceImpl implements UserOrderService {
    private final MerchantMapper merchantMapper;
    private final ShoppingCartMapper shoppingCartMapper;
    @Override
    public LocalDateTime getEstimatedDeliveryTime(Long shopId, String customerAddress) {
        //菜品制作时间
        Integer makeTime = shoppingCartMapper.getMakeTime(BaseContext.getCurrentId());
        log.info("菜品制作时间:{}",makeTime);

        Merchant byId = merchantMapper.findById(shopId);
        Map<String, String> map = MapUtils.gaodeTwoPointCostDistanceAndTimeByAddress(byId.getShopAddress(), customerAddress);
        String durationTime = map.get("duration");
        Long time = makeTime*60 + Long.valueOf(durationTime) + 600;
        log.info("预计送达时间：{}",time);
        LocalDateTime localDateTime = LocalDateTime.now().plusSeconds(time);
        return localDateTime;
    }
}
